﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PICOC
{
    public class PICOCStructure
    {
        public List<PICOCElement> Elements { get; set; }

        public PICOCStructure(params PICOCElement[] elements)
        {
            this.Elements = new List<PICOCElement>();

            foreach (PICOCElement e in elements)
                Elements.Add(e);
        }

        public String CreateQuery()
        {
            List<String> queries = new List<string>();

            foreach (PICOCElement element in Elements)
            {
                String query = "(\"" + element.Term + "\"";

                foreach (String syn in element.Synonyms)
                {
                    query += " OR \"" + syn + "\"";
                }
                query += ")";

                queries.Add(query);
            }

            if (queries.Count == 0)
                return String.Empty;

            String queryString = queries.First();

            for (int i = 1; i < queries.Count; i++)
            {
                queryString += " AND " + queries[i];
            }

            return queryString;
        }
    }
}
